﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TireService.Data
{
    /// <summary>
    /// Validation rules for Customer
    /// </summary>
    public partial class CustomerSubscription
    {
        TireServiceDB db = new TireServiceDB();

        /// <summary>
        /// Validation rules to ensure data is filled out in mandatory fields
        /// </summary>
        partial void OnValidate(System.Data.Linq.ChangeAction action)
        {
            if (this.CustomerId == null)
            {
                throw new ArgumentException("Kunde skal vælges.");
            }

            if (this.SubscriptionId == null)
            {
                throw new ArgumentException("Abonnement skal vælges.");
            }

            if (this.LastRenewalDate == null)
            {
                throw new ArgumentException("Seneste fornyelsesdato skal udfyldes.");
            }

            if (this.NextRenewalDate == null)
            {
                throw new ArgumentException("Næste fornyelsesdato skal udfyldes.");
            }

            if (this.Price == null)
            {
                throw new ArgumentException("Pris skal udfyldes.");
            }
        }

        /// <summary>
        /// Validation rule making sure that InActivationDate is also filled out if subscription is set to InActive
        /// </summary>
        /// <param name="value">new value for InActive</param>
        partial void OnInActiveChanging(bool value)
        {
            //// Check if value is changed
            //if (this.InActive != value)
            //{
            //    if (value == true & this.InActiveDate != null)
            //    {
            //        throw new ArgumentException("Deaktiveringsdato skal udfyldes ved deaktivering.");
            //    }
            //    else
            //    {
            //        if (value == false & this.InActiveDate != null)
            //        {
            //            throw new ArgumentException("Deaktiveringsdato skal ryddes ved genaktivering af abonnement.");
            //        }
            //    }
            //}
        }

        ///// <summary>
        ///// Validation rule making sure that LastRenewalDate is smaller than NextRenewalDate
        ///// </summary>
        ///// <param name="value">New value for LastRenewalDate</param>
        //partial void OnLastRenewalDateChanging(DateTime value)
        //{
        //    if (value > this.NextRenewalDate)
        //    {
        //        throw new ArgumentException("Seneste fornyelsesdato kan ikke være senere end næste fornyelsesdato.");
        //    }
        //}

        /// <summary>
        /// Validation rule making sure that NextRenewalDate is bigger than LastRenewalDate
        /// </summary>
        /// <param name="value"></param>
        partial void OnNextRenewalDateChanging(DateTime value)
        {
            if (value < this.LastRenewalDate)
            {
                throw new ArgumentException("Næste fornyelsesdato kan ikke være tidligere end seneste fornyelsesdato.");
            }
        }
    }
}
